#ifndef _S_NORFLASH_DRIVER_H_
#define _S_NORFLASH_DRIVER_H_

typedef enum
{
	norflash_OK = 0x00,
	norflash_powerdown_success,
	norflash_read_failed,
	norflash_write_failed,
	norflash_id_error,
	norflash_pagesize_error,
	norflash_size_not_matched,
	norflash_function_null_error,
	norflash_varify_failed,
	norflash_powerstandby_failed,
	norflash_powerdown_failed,
	norflash_waitready_failed,
}NorFlash_Result;

typedef struct __NorFlash_Handle
{
	unsigned char manId;
	unsigned char devId;
	unsigned int devSize;
	unsigned int pageSize;
	unsigned int sectorSize;
	unsigned int sectorCount;
	unsigned int blockSize;

	void (*norflash_select)(void);
	void (*norflash_deselect)(void);
	NorFlash_Result (*norflash_write)(const unsigned char *wdata, unsigned short length);
	NorFlash_Result (*norflash_read)(unsigned char *rdata, unsigned short length);
}NorFlash_Handle;


extern NorFlash_Result S_NorFlash_VarifyInfo(NorFlash_Handle norflash, unsigned char *manId, unsigned char *devId);
extern NorFlash_Result S_NorFlash_Open(NorFlash_Handle norflash);
extern NorFlash_Result S_NorFlash_Close(NorFlash_Handle norflash);
extern NorFlash_Result S_NorFlash_Read(NorFlash_Handle norflash, unsigned int offset, unsigned char *buf, unsigned short length);
extern NorFlash_Result S_NorFlash_Write(NorFlash_Handle norflash, unsigned int offset, unsigned char *buf, unsigned short length);
extern NorFlash_Result S_NorFlash_Erase(NorFlash_Handle norflash, unsigned int offset, unsigned short length);
extern NorFlash_Result S_NorFlash_ChipErase(NorFlash_Handle norflash);

#endif
